<?php

//include_once('superheader.php');

$m = new Mongo();

$db = $m->EMU;

$collection = $db->users;

$userQuery = array('user' =>  $_POST['username']);

$cursor = $collection->findOne($userQuery);


if($cursor == NULL && $_POST['password'] != "" && $_POST['username'] != "" && isset($_POST['role']))
{

	$collection->insert(array('user' => $_POST['username'], 'password' => $_POST['password'], 'role' => $_POST['role'], ));
	Header("Location: ../adminpannel.php");
}
else if($cursor != NULL)
{
	Header("Location: ../adminpanel.php?error=duplicateUser");
}
else {
	Header("Location: ../adminpanel.php?error=emptyUser");
}
?>